package com.ruoyi.task;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.websocket.WebSocketUsers;
import com.ruoyi.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 酒店的一些定时任务调度
 */
@Component("hotelTask")
public class HotelTask {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderRegisterMapper orderRegisterMapper;

    @Autowired
    OrderRegisterBankRecMapper orderRegisterBankRecMapper;

    @Autowired
    OrderRegisterAlipayRecMapper orderRegisterAlipayRecMapper;

    @Autowired
    OrderRegisterWeChatRecMapper orderRegisterWeChatRecMapper;

    @Autowired
    OrderRegisterJzjRecMapper orderRegisterJzjRecMapper;

    /**
     * 取出超过20分钟还没处理的订单
     */
    public void getOrdersUnprocessedOverTwentyMinutes() {
        List<String> overtimeList = orderMapper.getOrdersUnprocessedOverTwentyMinutes();
        if (overtimeList.size() > 0) {
            Map map = new HashMap();
            map.put("orderType", 4);
            map.put("message", "快超时了,赶快接单!");
            WebSocketUsers.sendMessageToUsersByText(JSONObject.toJSONString(map));
            for (String orderId : overtimeList) {
                Map map1 = new HashMap();
                map1.put("orderId", orderId);
                map1.put("overtimeRemind", 1);
                orderMapper.updateOrder(map1);
            }
        }
    }

    /**
     * 定时计算每日的 银行卡、微信、支付宝、结转金 支入、退款、支出的金额
     */
    public void calcRegisterRec() {
        String recDate = DateUtils.getDate1();
        Map map = new HashMap();
        map.put("recDate",recDate);
        map.put("inPrice",0);
        map.put("sealStatus",0);
        map.put("sealPrice",0);
        orderRegisterBankRecMapper.postAddBankRec(map);
        orderRegisterWeChatRecMapper.postAddWeChatRec(map);
        orderRegisterAlipayRecMapper.postAddAlipayRec(map);
    }
}
